<template>
  <div class="process-container">
    <div class="page-header">
      <h1>历史实例</h1>
      <p>共 {{ historyInstanceList.length }} 个已完成流程实例</p>
    </div>

    <div class="process-list">
      <div v-for="instance in historyInstanceList" :key="instance.processInstanceId" class="process-item">
        <div class="process-icon">
          <i class="fas fa-history"></i>
        </div>
        <div class="process-main">
          <h3>{{ instance.processDefinitionName }}</h3>
          <div class="process-meta">
            <span>发起人: {{ instance.starterNickName }}</span>
            <span>开始: {{ instance.startTime }}</span>
            <span>结束: {{ instance.endTime }}</span>
          </div>
          <div class="process-duration">
            <span>总耗时: {{ instance.duration }}</span>
          </div>
        </div>
        <div class="process-status">
          <span class="status status-completed">已结束</span>
          <button class="btn-text">
            <i class="fas fa-chart-bar"></i>
            分析
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {ref, onMounted} from "vue";
import {getAllHistoryProcessInstanceList} from "@/api/workflow/flowInstance";
import {isLoading} from "@/views/workflow/index";
import {message} from "@/utils/ElmessasgeUtils";

const historyInstanceList = ref([])


async function updateAllWorkflowInstanceList() {
  isLoading.value = true;
  await getAllHistoryProcessInstanceList().then((res: any) => {
    if (res.data.code == 200) {
      historyInstanceList.value = res.data.data;
    } else {
      message("获取历史实例失败", 'error');
    }
    isLoading.value = false;

  })
}

onMounted(async () => {
  await updateAllWorkflowInstanceList();
})
</script>


<style scoped>
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 页面头部 */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #1E293B;
  margin-bottom: 8px;
}

.page-header p {
  color: #64748B;
}

.task-main h3 {
  color: #1E293B;
  margin-bottom: 8px;
  font-weight: 600;
}


.status {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-completed {
  background: #ECFDF5;
  color: #e85f5f;
}

.btn-text {
  background: transparent;
  border: none;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748B;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-text:hover {
  color: #6366F1;
  background: #F8FAFC;
}

/* 流程列表 */
.process-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.process-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.process-item {
  background: white;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.process-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.process-icon {
  width: 48px;
  height: 48px;
  background: #F1F5F9;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  color: #6366F1;
  font-size: 1.2rem;
}

.process-main {
  flex: 1;
}

.process-main h3 {
  color: #1E293B;
  margin-bottom: 8px;
  font-weight: 600;
}

.process-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: #64748B;
}

.process-duration {
  font-size: 0.9rem;
  color: #64748B;
}

.process-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-left: 20px;
}

.deployed-processes h2 {
  color: #1E293B;
  margin-bottom: 16px;
  font-weight: 600;
}

</style>